Saves all currently open images in a folder using '001', '002', etc.
as the file names. The save file dialog box will be displayed once
(and only once) so that you can specify the folder to save the files in.
Leave the file name blank(e.g. SaveAs('')) to get a dialog box for each file.
}
var
n:integer;
begin
RequiresVersion(1.45);
for n:=1 to nPics do begin
SelectPic(n);
SaveAs(n:3);
{Export(n:3);}
end;
end;
macro 'Import FITS…';
{
This is an example of how to decode an image file header. In this case, the header is 2880 bytes long and bytes 266-269 contain the width(ASCII) and bytes
246-249 cantain the height. Refer to "FITS:A Flexible Image Transport System",
Astronomy and Astrophysics Supplement Series 44, 1981, 363-370.
}
var
width,height,offset,i,d,m:integer;
begin
width:=512;
height:=1;
offset:=0;
SetImport('8-bit');
SetCustom(width,height,offset);
Import(''); {Read in header as an image, prompting for the file name.}
if not ((GetPixel(108,0)=49) and (GetPixel(109,0)=54)) then begin
{BITPIX<>16}
PutMessage('This macro only reads 16-bit FITS files');
SelectPic(nPics); Dispose;
exit;
end;
m:=1000;
width:=0;
for i:=266 to 269 do begin
d:=GetPixel(i,0);
if d=32 then d:=48;
d:=d-48;
width:=width+d*m;
m:=m/10;
end;
m:=1000;
height:=0;
for i:=346 to 349 do begin
d:=GetPixel(i,0);
if d=32 then d:=48;
d:=d-48;
height:=height+d*m;
m:=m/10;
end;
SelectPic(nPics); {The ID of the last window opened is equal to nPics.}
Dispose;
offset:=2880;
SetImport('16-bit Signed; Calibrate; Autoscale');
SetCustom(width,height,offset);
Import(''); {No prompt this time; Import remembers the name.}
FlipVertical;
end;
macro 'Import Image TIFF File…';
{
As an example of how to import a foreign file format, this macro reads
the TIFF files created by Image. The format of an Image TIFF file
is described in Appendix E of the Image manual.
}
var
width,height,offset:integer;
begin
width:=768;
height:=1;
offset:=0;
SetImport('8-bit');
SetCustom(width,height,offset);
Import(''); {Read in header as an image, prompting for the file name.}
if not ((GetPixel(0,0)=77) and (GetPixel(0,0)=77)) then begin {'MM'}
PutMessage('This is not a TIFF file.');
SelectPic(nPics); Dispose;
exit;
end;
width := (GetPixel(30,0)*256) + GetPixel(31,0);
height := (GetPixel(42,0)*256) + GetPixel(43,0);
SelectPic(nPics); {The ID of the last window opened is equal to nPics.}
Dispose;
offset:=768;
SetCustom(width,height,offset);
Import(''); {No prompt this time; Import remembers the name.}
end;
macro 'Import Multiple Images per File…';
{
Imports a series of 256x256 images contained in a single file, in this
case an NIH Image stack with an arbitrary number of 256x256 slices.
}
var
offset,i,PicSize,HdrSize,width,height:integer;
begin
HdrSize:= 768;
width:= 256;
height:=256;
PicSize:=width*height;
offset:=HdrSize;
SetImport('8-bit');
for I:=1 to 100 do begin {Macro will terminate at eof}
SetCustom(width,height,offset);
Import('');
offset:=offset+PicSize;
end;
end;
macro 'Import PET…';
var
offset,i,PicSize,HdrSize,width,height:integer;
begin
HdrSize:= 0;
width:= 128;
height:=128;
PicSize:=width*height;
offset:=HdrSize;
SetImport('8-bit');
for I:=1 to 100 do begin {Macro will terminate at eof}
SetCustom(width,height,offset);
Import('');
offset:=offset+PicSize;
end;
end;
macro 'Convert Files…';
{
Converts a set of raw data files(all in the same folder) with names
in the form raw.001, raw.002, etc to TIFF or PICT. As long as the
converted files are saved in the same folder, you should
only see two file dialog boxes(one for the first Import and one for
the first SaveAs).
}
Var
i,nFiles:integer;
begin
nFiles:=GetNumber('Number of files:',5);
for i:=1 to nFiles do begin
Import('raw.',i:3);
SetPicName('file',i:3);
SaveAs;
Dispose;
end;
end;
macro 'Import IPLab File';
var
width,height,offset:integer;
begin
width:=100;
height:=1;
offset:=0;
SetImport('8-bit');
SetCustom(width,height,offset);
Import(''); {Read in header as an image, prompting for file name.}
width := (GetPixel(8,0)*256) + GetPixel(9,0);
height := (GetPixel(12,0)*256) + GetPixel(13,0);
Dispose;
offset:=2120; {The IPLab offset}
SetImport('16-bit Signed; Calibrate; Autoscale');
SetCustom(width,height,offset);
Import(''); {No prompt this time; Import remembers the name.}
end;
procedure ShowBioRadInfo;
{Displays the contents of the 480(?) byte header at}
{the end of Biorad MRC 600 Z Series files.}
var
InfoSize,count:integer;
ch:string;
begin
InfoSize:=480;
SetCustom(InfoSize,1,HdrSize+Width*Height);
Import('');
GetRow(0,0,InfoSize);
Dispose;
SetNewSize(460,100);
SetForeground(255);
SetBackground(0);
MakeNewWindow('Info');
SetCursor('Watch');
SetFont('Monaco');
SetText('With background; Left Justified');
SetFontSize(12);
count:=0;
MoveTo(8,20);
for i:=1 to InfoSize do begin
ch:=chr(LineBuffer[i-1]);
if (ord(ch)=13) or (count>60) then begin
writeln(ch);
count:=0;
end else begin
if (ord(ch)>=32) and (ord(ch)<=126) then begin
write(ch);
count:=count+1;
end;
end;
end;
end;
macro 'Import Biorad MRC 600 Z Series…';
{
Imports a Z series(multiple images per file) from a Biorad MRC 600
confocal microscope. The width, height and number of images are
extracted from the first 3 16-bit word in the 76 byte header and
the file name is extracted from bytes 18-23 of the header.
}
var
width,height,nImages,offset:integer;
HdrSize,i,start,PicSize,stack:integer;
n1,n2,n3,n4,n5,n6:string;
begin
{RequiresVersion(1.48);}
width:=512;
height:=1;
offset:=0;
SetImport('8-bit');
SetCustom(width,height,offset);
Import(''); {Read header}
width:=GetPixel(0,0)+GetPixel(1,0)*256;
height:=GetPixel(2,0)+GetPixel(3,0)*256;
nImages:=GetPixel(4,0)+GetPixel(5,0)*256;
n1:=chr(GetPixel(18,0));
n2:=chr(GetPixel(19,0));
n3:=chr(GetPixel(20,0));
n4:=chr(GetPixel(21,0));
n5:=chr(GetPixel(22,0));
n6:=chr(GetPixel(23,0));
Dispose;
HdrSize:= 76;
if (width<128) or (width>2048) or (height<128) or (height>2048) or (nImages<1) or (nImages>256) then begin
PutMessage('This does not seem to be a Biorad MRC 600 Z Series file.');
exit;
end;
PicSize:=width*height;
start:=GetNumber('Starting image:',1);
offset:=HdrSize+(start-1)*PicSize;
SetNewSize(width,height);
MakeNewStack(n1,n2,n3,n4,n5,n6,'[',start:1,']');
stack:=nPics;
for i:=start to start+nImages-1 do begin
SetCustom(width,height,offset);
Import('');
Invert;
ChangeValues(0,0,1);
ChangeValues(255,255,254);
offset:=offset+PicSize;
SetPicName(i:3);
SelectAll;
Copy;
Dispose;
SelectPic(stack);
if i<>start then AddSlice;
Paste;
end;
KillRoi;
ShowBioRadInfo;
end;
macro 'Import from IBAS';
var
width,height,offset:integer;
begin
width:=128;
height:=1;
offset:=0;
SetImport('8-bit');
SetCustom(width,height,offset);
Import(''); {Read in header as an image, prompting for file name.}
width := (GetPixel(7,0)*256) + GetPixel(6,0);
height := (GetPixel(9,0)*256) + GetPixel(8,0);
Dispose(nPics); {The ID of the last window opened = nPics.}
offset:=128; {The IBAS offset}
SetImport('8-bit; Calibrate; Autoscale');
SetCustom(width,height,offset);
Import(''); {No prompt this time; Import remembers the name.}
Invert
SetScaling ('Bilinear');
SetScaling ('New Window');
ScaleAndRotate (0.80, 1.0, 0);
end;
macro 'Import 64x64x64 SPECT Image…';
{Imports a 64x64x64x16-bit headerless SPECT image into a stack.}
var
width,height,nImages,offset:integer;
HdrSize,i,PicSize,stack:integer;
begin
RequiresVersion(1.48);
width:=64;
height:=64;
nImages:=64;
HdrSize:= 0;
offset:=HdrSize;
PicSize:=width*height*2;
SetNewSize(width,height);
MakeNewStack('Stack');
MoveWindow(160,40);
stack:=nPics;
SetImport('16-bit Unsigned, Swap Bytes');
{SetImportMinMax(0,2500);} {Uncomment to fix scale}
for i:=1 to nImages do begin
SetCustom(width,height,offset);
Import('');
offset:=offset+PicSize;
SelectAll;
Copy;
Dispose;
SelectPic(stack);
if i>1 then AddSlice;
Paste;
end;
KillRoi;
end;
macro 'Import 8-bit 3D Image…';
var
width,height,nImages,offset:integer;
HdrSize,i,PicSize,stack:integer;
begin
RequiresVersion(1.48);
width:=GetNumber('Width:',256);
height:=GetNumber('Height:',256);
nImages:=GetNumber('Depth(number of slices):',128);